package cn.jane.bigevent.mapper;

import cn.jane.bigevent.entity.Category;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface CategoryMapper {

    @Insert("""
            INSERT INTO category (category_name, category_alias, create_user, create_time, update_time)
            VALUES (#{categoryName}, #{categoryAlias}, #{createUser}, #{createTime}, #{updateTime})
            """)
    void add(Category category);

    @Select("""
            SELECT * FROM category WHERE create_user = #{userId}
            """)
    List<Category> list(int userId);

    @Select("""
            SELECT * FROM category WHERE id = #{id}
            """)
    Category findById(int id);

    @Update("""
            UPDATE category
            SET category_name = #{categoryName}, category_alias = #{categoryAlias}, update_time = #{updateTime}
            WHERE id = #{id}
            """)
    void update(Category category);

    @Delete("""
            DELETE FROM category WHERE id = #{id}
            """)
    void delete(int id);
}
